package com.sh.demo.qa.util;

import flexjson.JSONSerializer;

public class JsonUtil {

	/**
	 * 输出成Json
	 * @param response
	 * @param saveParam 保留的属性
	 * @param filterParam 过滤的属性，遇到列表其后的属性是列表中元素的属性，比如:list.videoFile，实际上是list -> video -> videoFile
	 * @param result
	 * @return
	 * @throws Exception
	 */
	public static String outputJsonByFilter( String saveParam, String filterParam, Object result, Boolean isDeep) throws Exception {
		JSONSerializer serializer =  new JSONSerializer().exclude("*.class");
		if(null != saveParam && !saveParam.trim().equals("")){
			String[] params = saveParam.split(",");
			serializer.include(params);
		}
		if(null != filterParam && !filterParam.trim().equals("")){
			String[] params = filterParam.split(",");
			serializer.exclude(params);
		}
		if(isDeep){
			return serializer.deepSerialize(result);
		}else{
			return serializer.serialize(result);
		}
	}
}
